package cn.ch.system.listener;

import cn.ch.system.service.IPermissionScanService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
/*实现Listener接口，并打上注解*/
public class PermissionScanListener implements ServletContextListener {
    @Autowired
    private IPermissionScanService permissionScanService;
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        //通过线程来实现
        new Thread(new Runnable() {
            @Override
            public void run() {
                permissionScanService.annoScan();
            }
        }).start();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        //用于监听器销毁，可以不用写
    }
}
